1 /* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.util.concurrent; 18 19 import com.google.common.annotations.Beta; 20 21 import java.util.concurrent.ExecutionException; 22 import java.util.concurrent.Future; 23 24 /** 25 * Provides a backup {@code Future} to replace an earlier failed {@code Future}. 26 * An implementation of this interface can be applied to an input {@code Future} 27 * with {@link Futures#withFallback}. 28 * 29 * @param <V> the result type of the provided backup {@code Future} 30 * 31 * @author Bruno Diniz 32 * @since 14.0 33 */ 34 @Beta 35 public interface FutureFallback<V> { 36 /** 37 * Returns a {@code Future} to be used in place of the {@code Future} that 38 * failed with the given exception. The exception is provided so that the 39 * {@code Fallback} implementation can conditionally determine whether to 40 * propagate the exception or to attempt to recover. 41 * 42 * @param t the exception that made the future fail. If the future's {@link 43 * Future#get() get} method throws an {@link ExecutionException}, then the 44 * cause is passed to this method. Any other thrown object is passed 45 * unaltered. 46 */ 47 ListenableFuture<V> create(Throwable t) throws Exception; 48 }